#pragma once

class GameState
{
public:
	// constructor.
	GameState():handled(false) {}

	// destructor.
	virtual ~GameState() {}

	// enter state
	virtual void OnEnter() {}

	// update
	virtual void OnUpdate(float frameTime) {}

	// render
	virtual void OnPreRender() {}

	// leave state
	virtual void OnLeave() {}

	virtual bool OnKeyDown(const Windows::System::VirtualKey& Key) { return false; }

	virtual bool OnKeyUp(const Windows::System::VirtualKey& Key) { return false; }

	virtual bool OnPointerMoved(Windows::UI::Core::PointerEventArgs^ args) { return false; };

	virtual bool OnPointerPressed(Windows::UI::Core::PointerEventArgs^ args) { return false; };

	virtual bool OnPointerReleased(Windows::UI::Core::PointerEventArgs^ args) { return false; };

	//// net closed
	//virtual void OnDisconnect() {}
public:
	bool handled;
};


ref class StateMachine : public SingletonRef<StateMachine>
{
	friend SingletonRef;
private:
	StateMachine(){};
internal:
	void ChangeState(std::shared_ptr<GameState> new_state)
	{
		if (new_state != current_state)
		{
			if (current_state)
			{
				current_state->OnLeave();
			}

			current_state = new_state;

			if (current_state)
			{
				current_state->OnEnter();
			}
		}
	}

	void Update(float frameTime)
	{
		if (current_state)
		{
			current_state->OnUpdate(frameTime);
		}
	}

	void PreRender()
	{
		if (current_state)
			current_state->OnPreRender();
	}

	std::shared_ptr<GameState> CurrentState()
	{
		return current_state;
	}

	//void OnDisconnect()
	//{
	//	if (current_state)
	//		current_state->OnDisconnect();
	//}

private:
	std::shared_ptr<GameState> current_state;
};
